<?php

declare(strict_types=1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use \think\facade\Db;
use think\facade\Cache;

class genfield extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('app\command\genfield')
            ->setDescription('the app\command\genfield command');
    }

    protected function execute(Input $input, Output $output)
    {
        Db::table('admin_budget')->chunk(100, function ($rows) {
            foreach ($rows as $row) {
                $key = $row['functional_category_code_class'] . $row['functional_category_code_fund'] . $row['functional_category_code_item'];
                $is = Cache::get('r' . $key);
                if (!$is) {
                    echo $key . "\n";
                    Cache::store('redis')->set('r' . $key, '1', 7200);
                    $field = 'reason' . $key;
                    $sql = "alter table admin_test add " . $field . " varchar(255) not null default ''";
                    Db::query($sql);
                }
            }
        });
        var_dump($GLOBALS['i']);
        // 指令输出
        $output->writeln('app\command\genfield');
    }
}
